//
//  ContentViewController.m
//  1227-163MusicDemo
//
//  Created by 千锋 on 15/12/27.
//  Copyright (c) 2015年 千锋. All rights reserved.
//

#import "ContentViewController.h"
#import "LeftViewController.h"
#import "CenterViewController.h"
#import "RightViewController.h"

//屏幕尺寸
#define SCREEN_SIZE [UIScreen mainScreen].bounds.size



@interface ContentViewController ()
{
    LeftViewController * _leftVC;//左侧视图控制器
    CenterViewController * _centerVC ;//中间当前显示的视图控制器
    RightViewController * _rightVC;//右侧视图控制器
}
//记录当前视图控制器
@property(nonatomic,strong)UIViewController * currentVC;
@end

@implementation ContentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.view.backgroundColor = [UIColor orangeColor];
    //创建子视图控制器
    _leftVC = [[LeftViewController alloc]init];
    _centerVC = [[CenterViewController alloc]init];
    _centerVC.view.backgroundColor = [UIColor orangeColor];
    _rightVC = [[RightViewController alloc]init];
    [self addChildViewController:_leftVC];
    _leftVC.view.backgroundColor = [UIColor redColor];
    [self addChildViewController:_rightVC];
    _rightVC.view.backgroundColor = [UIColor grayColor];
    //显示当前视图控制器
    [self addChildViewController:_centerVC];
    _currentVC = _centerVC;
    [self.view addSubview:_centerVC.view];
    [self cumtomNavi];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



-(void)makePosition{
    
    
}

-(void)cumtomNavi{
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(leftItemClicked:)];
    UIBarButtonItem * rightItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(rightItemClicked:)];
    self.navigationItem.leftBarButtonItem = leftItem;
    self.navigationItem.rightBarButtonItem = rightItem;
    
}

//@selector
//左侧按钮点击响应事件
-(void)leftItemClicked:(UIBarButtonItem *)sender{
    NSLog(@"left");
    //如果当前视图控制器不是本身就可以切换，否则不能切换
    if (![_currentVC isKindOfClass:[_leftVC class]]) {
        [self transitionFromViewController:_currentVC toViewController:_leftVC duration:2 options:UIViewAnimationOptionCurveEaseIn animations:^{
            _leftVC.view.frame = self.view.bounds;
            _centerVC.view.frame = CGRectMake(SCREEN_SIZE.width, 0, SCREEN_SIZE.width, SCREEN_SIZE.height);
        } completion:^(BOOL finished) {
            if (finished) {
                _currentVC = _leftVC;
                NSLog(@"finished:%d",finished);
            }
        }];
    }
}

-(void)rightItemClicked:(UIBarButtonItem *)sender{
    NSLog(@"right");
    if (![_currentVC isKindOfClass:[_rightVC class]]) {
        [self transitionFromViewController:_currentVC toViewController:_rightVC duration:0.5 options:UIViewAnimationOptionCurveEaseOut animations:nil completion:^(BOOL finished) {
            if (finished) {
                _currentVC = _rightVC;
            }
        }];
    }
}

@end














